package com.hnevc.viewpagedemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final List<Fragment> fragmentList=new ArrayList<>();
        fragmentList.add(new BlankFragment());
        fragmentList.add(new BlankFragment1());
        fragmentList.add(new BlankFragment2());

        FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }
        };
        ViewPager viewPager= (ViewPager) findViewById(R.id.vp);
        viewPager.setAdapter(fragmentPagerAdapter);
    }
}
